package com.commodity.utils;

import com.alibaba.fastjson2.JSON;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class ServletUtils {
    public static void renderJson(Object object, HttpServletResponse resp) {
        //声明响应的数据库json格式
        resp.setContentType("application/json;charset=utf-8");

        //将studentList序列化成json字符串
        String json = JSON.toJSONString(object);

        try {
            PrintWriter out = resp.getWriter();
            out.write(json);
            out.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
